<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
	<meta http-equiv="Cache-Control" content="no-siteapp" />
	<link rel="Bookmark" href="__ADMIN__/favicon.ico" >
	<link rel="Shortcut Icon" href="__ADMIN__/favicon.ico" />
	<!--[if lt IE 9]>
	<script type="text/javascript" src="__ADMIN__/lib/html5.js"></script>
	<script type="text/javascript" src="__ADMIN__/lib/respond.min.js"></script>
	<![endif]-->
	<link rel="stylesheet" type="text/css" href="__ADMIN__/static/h-ui/css/H-ui.min.css" />
	<link rel="stylesheet" type="text/css" href="__ADMIN__/static/h-ui.admin/css/H-ui.admin.css" />
	<link rel="stylesheet" type="text/css" href="__ADMIN__/lib/Hui-iconfont/1.0.8/iconfont.css" />
	<link rel="stylesheet" type="text/css" href="__ADMIN__/static/h-ui.admin/skin/default/skin.css" id="skin" />
	<link rel="stylesheet" type="text/css" href="__ADMIN__/static/h-ui.admin/css/style.css" />
	<link rel="stylesheet" type="text/css" href="__ADMIN__/static/plugs/css/jquery-editable-select.css" />
	<link href="__ADMIN__/static/plugs/css/select2.min.css" rel="stylesheet" />
	<!--[if IE 6]>
	<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
	<script>DD_belatedPNG.fix('*');</script>
	<![endif]-->
	<!--/meta 作为公共模版分离出去-->

	<title>新增项目</title>
	<meta name="keywords" content="H-ui.admin v3.0,H-ui网站后台模版,后台模版下载,后台管理系统模版,HTML后台模版下载">
	<meta name="description" content="H-ui.admin v3.0，是一款由国人开发的轻量级扁平化网站后台模板，完全免费开源的网站后台管理系统模版，适合中小型CMS后台系统。">
</head>
<body>
<article class="page-container">
	<form action="update" method="post" class="form form-horizontal" id="form-project-add">
		<input type="hidden" value="{$project.id}" name="id">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>项目名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$project.pname}" placeholder="" id="" name="pname">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>项目类型：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<span class="select-box">
				<select id="project_type_select" name="ptype" class="select" >
<!--					<option value="0" {eq value= "未分类"  name="$project.ptype"} selected {/eq}>未分类</option>-->
<!--					<option value="1" {eq value= "专题"  name="$project.ptype"} selected {/eq}>专题</option>-->
<!--					<option value="2" {eq value= "频道"  name="$project.ptype"} selected {/eq}>频道</option>-->
<!--					<option value="3" {eq value= "分网"  name="$project.ptype"} selected {/eq}>分网</option>-->
<!--					<option value="4" {eq value= "建站"  name="$project.ptype"} selected {/eq}>建站</option>-->
<!--					<option value="5" {eq value= "系统"  name="$project.ptype"} selected {/eq}>系统</option>-->
				</select>
				</span>
			</div>
		</div>

		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>CMS类型：</label>
			<div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
				<select name="cms" class="select" id="cms_type_select">
<!--					<option value="1" {eq value= "阳光网CMS"  name="$project.cms"} selected {/eq}>阳光网CMS</option>-->
<!--					<option value="2" {eq value= "TRS"  name="$project.cms"} selected {/eq}>TRS</option>-->
<!--					<option value="3" {eq value= "织梦"  name="$project.cms"} selected {/eq}>织梦</option>-->
				</select>
				</span>
			</div>
		</div>

		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>开发人员：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<select class="select" name="person" id="person_filter">
					{volist name='users' id='vo' key='k'}
						<option value="{$vo.id}" {eq value="$project.person" name="$vo.id"}selected{/eq} >{$vo.name}</option>
					{/volist}
				</select>

			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>开发语言：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<select name="lang[]" class="select"  multiple="multiple" id="lang_multiselect">
<!--					<option value="1">php</option>-->
<!--					<option value="2">java</option>-->
<!--					<option value="3">python</option>-->
<!--					<option value="4">asp</option>-->
<!--					<option value="5">javascript</option>-->
<!--					<option value="6">vue.js</option>-->
				</select>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>框架：</label>
			<div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
				<select name="frame" class="select" id="frame_filter">
<!--					<option value="1" {eq value="spring+hibernate+struts2" name="$project.frame"}selected{/eq}>spring+hibernate+struts2</option>-->
<!--					<option value="2" {eq value="spring+hibernate+xwork2.0" name="$project.frame"}selected{/eq}>spring+hibernate+xwork2.0</option>-->
<!--					<option value="3" {eq value="spring+mybatis+springmvc" name="$project.frame"}selected{/eq}>spring+mybatis+springmvc</option>-->
<!--					<option value="4" {eq value="Thinkphp" name="$project.frame"}selected{/eq}>Thinkphp</option>-->
<!--					<option value="5" {eq value="codeigniter" name="$project.frame"}selected{/eq}>codeigniter</option>-->
				</select>
				</span>
			</div>
		</div>

		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>前台地址：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$project.front_url}" placeholder="" id="" name="front_url">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>后台地址：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$project.back_url}" placeholder="" id="" name="back_url">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">服务器地址：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$project.srv_url}" placeholder="" id="" name="srv_url">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">git地址：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$project.git}" placeholder="" id="" name="git">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">ftp目录：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$project.ftp}" placeholder="" id="" name="ftp">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">代码目录：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$project.code_path}" placeholder="" id="" name="code_path">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">关联信息：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<textarea name="relate_info" cols="" rows="" class="textarea"  placeholder="请输入..." datatype="*10-100" maxlength="200" dragonfly="true" nullmsg="备注不能为空！" onKeyUp="textarealength(this,200)">{$project.relate_info}</textarea>
				<p class="textarea-numberbar"><em class="textarea-length">-</em>/200</p>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">项目描述：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<textarea name="desc" cols="" rows="" class="textarea"  placeholder="请输入..." datatype="*10-100" maxlength="200" dragonfly="true" nullmsg="备注不能为空！" onKeyUp="textarealength(this,200)">{$project.desc}</textarea>
				<p class="textarea-numberbar"><em class="textarea-length">-</em>/200</p>
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
				<!--				<button onClick="article_save_submit();" class="btn btn-primary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i> 保存并提交审核</button>-->
				<button class="btn btn-primary radius" type="submit" aria-hidden="true" data-dismiss="modal">&nbsp;&nbsp;提交&nbsp;&nbsp; </button>
<!--				<button class="btn btn-default radius" type="button" aria-hidden="true" data-dismiss="modal">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>-->
			</div>
		</div>
	</form>
</article>

<!--_footer 作为公共模版分离出去-->
{include file="footer"}
<!--/_footer /作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<!--<script type="text/javascript" src="__ADMIN__/lib/My97DatePicker/4.8/WdatePicker.js"></script>-->
<script type="text/javascript" src="__ADMIN__/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__ADMIN__/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__ADMIN__/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="__ADMIN__/lib/webuploader/0.1.5/webuploader.min.js"></script>
<script type="text/javascript" src="__ADMIN__/static/plugs/js/jquery-editable-select.js"></script>
<script type="text/javascript" src="__ADMIN__/static/plugs/js/select2.min.js"></script>
<script type="text/javascript">
	$(function(){
		$('.skin-minimal input').iCheck({
			checkboxClass: 'icheckbox-blue',
			radioClass: 'iradio-blue',
			increaseArea: '20%'
		});

		// 下拉单选框，可输入
		// $('#cms_type_select').editableSelect({ filter: false });
		// $('#frame_filter').editableSelect({ filter: false });
		$('#person_filter').select2();
		// 下拉多选框，不可输入
		$('#lang_multiselect').select2();

		$("#form-project-add").validate({
			rules: {
				pname:{required: true},
				ptype:{required: true},
				cms:{required: true},
				person:{required: true},
				lang:{required: true},
				frame:{required: true},
				front_url:{required: true},
				back_url:{required: true},
			},
			onkeyup: false,
			focusCleanup: true,
			success: 'valid',
			submitHandler: function (form) {
				$(form).ajaxSubmit({
					success: function (data) {
						console.log(data);
						if (data.code===0){
							var index = parent.layer.getFrameIndex(window.name);
							window.parent.location.reload();    // 刷新父页面
							parent.layer.close(index);          // 关闭当前的modal框
							// console.log(data);
						}else if (data.code=='4003'){
							layer.msg(data.message, {icon: 5, time:1000})
						}else {
							layer.msg(data.message, {icon: 5, time:1000})
						}
					}
				})
			}
		});

		let project = {$project};
		// getLangSelected(project);

		/*
		* 更新数据时回显开发语言多选项
		* */
		function getLangSelected(project, langobj) {
			// var langobj = {
			// 	'php': '1',
			// 	'java': '2',
			// 	'python': '3',
			// 	'asp': '4',
			// 	'javascript': '5',
			// 	'vue.js': '6',
			// };
			// 构造数据结构
			let tmp_obj = {};
			for (i of langobj){
				tmp_obj[i.name] = i.id;
			}

			console.log(tmp_obj);
			if (project.lang.length == 0){
				return;
			}
			let lang_arr = project.lang.split(',');	// 后台返回的"php,java" 分割成数组[ php, java ]
			let val_list = [];
			for (let i = 0; i < lang_arr.length; i++) {
				val_list.push(tmp_obj[lang_arr[i]]);		// 将后台所保存的数据转换成【id1,id2】的形式
			}
			console.log('val_list', val_list);
			// $('#lang_multiselect').val([5,6]).prop('selected');
			// $('#lang_multiselect').select2('val',['4', '6']);
			$('#lang_multiselect').val(val_list).trigger('change');
		}

		/*
		* 异步获取可选项的专用接口
		* */
		$.ajax({
			'type': 'GET',
			'url': "{:url('admin/project/get_all_options')}",
			'success': function (res) {
				type_select(res);
			},
			'error': function () {
				console.log('错误');
			}
		});

		/*
		* 用于页面中 select下拉框 可选项以及选择项的动态渲染
		* */
		function type_select(res) {
			console.log(res);
			let project_select_obj = document.getElementById('project_type_select');
			let cms_select_obj = document.getElementById('cms_type_select');
			let lang_select_obj = document.getElementById('lang_multiselect');
			let frame_select_obj = document.getElementById('frame_filter');

			for (let o of res) {
				if (o.type == "项目类型") {
					for (let i of o.value) {
						let option = new Option(i.name, i.id);
						// 判断项目的ptype，该ptype（中文而非数字）对应的为{id: xxx, name: "项目类型名称"}中的name字段
						if (project.ptype == i.name){
							option.selected = true;
						}
						project_select_obj.appendChild(option);
					}
				} else if (o.type == "cms类型") {
					for (let i of o.value) {
						let option = new Option(i.name, i.id);
						if (project.cms == i.name){
							option.selected = true;
						}
						cms_select_obj.appendChild(option);
					}
				}else if (o.type == "开发语言"){
					for (let i of o.value) {
						let option = new Option(i.name, i.id);
						lang_select_obj.appendChild(option);
					}
					// 开发语言为多选
					getLangSelected(project, o.value);

				}else if (o.type =='框架'){
					for (let i of o.value) {
						let option = new Option(i.name, i.id);
						if (project.frame == i.name){
							option.selected = true;
						}
						frame_select_obj.appendChild(option);
					}
				}
			}
			// select_obj.options[select_obj.options.length] = new Option('Text 1', 'Value1');
		}


});
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>